import Mock from "mockjs";
import { param2Obj } from "../utils/myUtils";
let list = [];
for (let i = 0; i < 100; i++) {
  let count = 1;
  list.push({
    id: Mock.mock("@id()"),
    grade: "VIP" + Mock.mock("@integer(1, 3)"),
    name: Mock.mock("@cname"),
    phone: Mock.mock("@integer(10000000000, 19999999999)"),
    age: Mock.mock("@integer(10,80)"),
    sex: Mock.mock("@integer(1, 2)"),
    date: Mock.mock("@datetime"),
    doctor: Mock.mock("@cname"),
    state: Mock.mock("@integer(1, 3)"),
    case: {
      a1: Mock.mock("@integer(1, 3)"),
      a2: Mock.mock("@integer(4, 6)"),
      a3: Mock.mock("@integer(7, 9)"),
      a4: Mock.mock("@integer(10, 12)"),
      a5: Mock.mock("@integer(13, 15)"),
    },
  });
}

export default {
  //获取数据接口
  getWorkData: (config) => {
    let { search, page, pageSize } = param2Obj(config.url);
    let newlist = list.filter((item) => {
      if (!Number(search)) {
        // 如果不是数字
        return item.name.indexOf(search) != -1;
      } else {
        //如果是数字
        return (item.phone + "").indexOf(search) != -1;
      }
    });
    //分页逻辑
    let newlist2 = newlist.filter((item, index) => {
      return (page - 1) * pageSize <= index && index < page * pageSize;
    });
    return {
      code: 200,
      msg: "请求成功",
      data: newlist2,
      total: list.length,
    };
  },

  // 接诊修改按钮
  setWorkState: (config) => {
    let id = config.body;
    list.forEach((item) => {
      if (item.id == id) {
        if (item.stata < 3) {
          item.state += 1;
        } else {
          item.state = (item.state % 3) + 1;
        }
      }
    });
    return {
      code: 200,
      msg: "更改成功",
      data: null,
    };
  },

  // 查询个人信息
  getOneName: (config) => {
    let id = config.body;
    let newlist3 = list.filter((item) => {
      return item.id.indexOf(id) != -1;
      // console.log(item.id.indexOf(id));
    });
    // console.log(newlist3);
    return {
      code: 200,
      msg: "查询成功",
      data: newlist3,
    };
  },
};
